package com.sgb.kjwl.view.ui.adapter.self.carMasters;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.CarriagePushEntity;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.NumberUtil;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 2021/8/10 10:12
 * @Description: 历史承运适配器
 */
public class CarriagePushHistoryAdapter extends BaseQuickAdapter<CarriagePushEntity, BaseViewHolder> {

    public CarriagePushHistoryAdapter(@Nullable List<CarriagePushEntity> data) {
        super(R.layout.item_carriage_push_history, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder helper, CarriagePushEntity item) {
        helper.setText(R.id.tv_item_cph_place, String.format("%s %s ➞ %s %s",
                item.getCityName(),
                item.getDistrictName(),
                item.getDestCityName(),
                item.getDestDistrictName()))
                .setText(R.id.tv_item_cph_car, String.format("%s/%s",
                        item.getCarTypeName(),
                        item.getCarLenName()))
                .setText(R.id.tv_item_cph_date, String.format("%s-%s",
                        DateUtils.stampToDay5(item.getShipmentStartTime()),
                        DateUtils.stampToDay5(item.getShipmentEndTime())))
                .setText(R.id.tv_item_cph_freight, String.format("%s 元%s",
                        NumberUtil.trim0(item.getFreight()),
                        item.getFreightUnitWords()));
        //消息状态 1:生效/2:失效
        if ("1".equals(item.getMessageStatus())) {
            helper.setImageResource(R.id.iv_item_cph_status, R.drawable.ic_take_effect);
        } else if ("2".equals(item.getMessageStatus())) {
            helper.setImageResource(R.id.iv_item_cph_status, R.drawable.ic_take_effect_un);
        } else {
            helper.setImageResource(R.id.iv_item_cph_status, R.color.transparent);
        }
        //承运类型
        if (item.getCarrierType() == null || item.getCarrierType() == 1) {
            //普通承运
            helper.setImageResource(R.id.iv_item_cph_type, R.drawable.carrier_ordinary);
        } else if (item.getCarrierType() == 2) {
            //竞价承运
            helper.setImageResource(R.id.iv_item_cph_type, R.drawable.carrier_bidding);
        } else if (item.getCarrierType() == 3) {
            //特价承运
            helper.setImageResource(R.id.iv_item_cph_type, R.drawable.carrier_special_offer);
        } else {
            helper.setImageResource(R.id.iv_item_cph_type, R.drawable.carrier_ordinary);
        }
    }
}
